﻿Public Class PresentationUtilities
    Public Shared Function ShowControlAsDialogWindow(ByVal control As Control, Optional ByVal caption As String = "", Optional ByVal style As WindowStyle = WindowStyle.ToolWindow) As Boolean?
        Dim w As New Window
        w.Content = control
        w.SizeToContent = SizeToContent.WidthAndHeight
        w.WindowStyle = style
        w.Title = caption
        Return w.ShowDialog()
    End Function

    Public Shared Sub ShowStandardMessage(message As StandardMessages)
        Select Case message
            Case StandardMessages.CASignatureInvalid
                MessageBox.Show("Error! The CA reply to your query failed the signature verification. The CA has been compromised!", "Signature invalid", MessageBoxButton.OK, MessageBoxImage.Error)
            Case StandardMessages.ClientUnknown
                MessageBox.Show("Error! The CA reports that it doesn't know you yet. Please register to the CA by requesting a signature certificate before doing anything else.", "Client unknown", MessageBoxButton.OK, MessageBoxImage.Information)
            Case StandardMessages.CommunicationFailed
                MessageBox.Show("Communication with the CA failed. Make sure the CA application is running and that there are no firewalls blocking the TCP/IP communication for the Client or the CA", "Failed to contact CA", MessageBoxButton.OK, MessageBoxImage.Error)
            Case StandardMessages.ClientSignatureInvalid
                MessageBox.Show("Error! The CA reports that the signature verification failed! This means the Client didn't sign the request properly, or that the CA couldn't verify the signature for some reason. Either way this is a bug, please report it.", "Signature invalid", MessageBoxButton.OK, MessageBoxImage.Error)
        End Select
    End Sub
End Class
